import apps from './app'
// import actions from './state'
import { registerMicroApps, addGlobalUncaughtErrorHandler } from 'qiankun'
console.log('registerMicroApps', apps)

// registerMicroApps 第二个参数能够不要，若是要作点啥，就写到对应的地方
export function registerApps() {
  try {
    registerMicroApps(apps, {
      beforeLoad: [
        app => {
          console.log('before load', app)
        }
      ],
      beforeMount: [
        app => {
          console.log('before mount', app)
        }
      ],
      afterUnmount: [
        app => {
          console.log('before unmount', app)
        }
      ]
    })
  } catch (err) {
    console.log(err)
  }
}

// 出错时显示的内容
addGlobalUncaughtErrorHandler((event) => {
  const { message } = event
  if (message && message.includes('died in status LOADING_SOURCE_CODE')) {
    console.log('微应用加载失败，请检查应用是否可运行')
  }
})